<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta http-equiv="Expires" content="0">
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="Cache-control" content="no-cache">
  <meta http-equiv="Cache" content="no-cache">
  <title>App 下载</title>
  <link rel="stylesheet" href="./styles/index.css">
</head>

<style>
  .container {
    display: none;
  }
  .row-1 {
    width: 100%;
    height: 48px;
    padding: 0 20px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
  .row-1 img {
    --size: 32px;
    width: var(--size);
    height: var(--size);
  }
  .row-1 p {
    font-size: 16px;
    color: #333333;
    margin-right: 16px;
  }

  .row-2 {
    width: 100%;
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .row-2 img {
    width: 70%;
  }
</style>


<body>
  <div class="container">
    <div class="row-1">
      <p>点击右上角 [...] 在浏览器中打开</p>
      <img src="./assets/arrow.png" alt="">
    </div>

    <div class="row-2">
      <img src="./assets/open_in_browser.png" alt="">
    </div>
  </div>
</body>


<script type="module">
  import { browser, getQueryString } from './utils/index.js';
  import { apiGetAppVersions } from './api/noauth.js';

  let data = {
    is_wechat: false,
    app_url: '',
  };

  // 获取 app 地址并下载
  function downloadApp(channel) {
    apiGetAppVersions({ keys: `oem_configs,data,${channel}`}, function (res) {
      const isHttps = window.location.protocol === 'https:';
      data.app_url = res ? (isHttps ? res.url : (res.urlHttp || res.url)) : '';
      if (!data.app_url) return;
      window.open(data.app_url, '_self');
    }, function (err) {
    });
  }

  function init() {
    data.is_wechat = browser.versions.weixin;
    // 是否微信端
    if (data.is_wechat) {
      const elem = document.querySelector('.container');
      elem.style.display = 'block';
    } else {
      const channel = getQueryString('ch') || 'general';
      downloadApp(channel);
    }
  }

  init();
</script>
</html>
